package com.beiing.tianshuai.tianshuai.huodong.presenter;

import com.beiing.tianshuai.tianshuai.base.BasePresenter;
import com.beiing.tianshuai.tianshuai.entity.HuoDongItemBean;
import com.beiing.tianshuai.tianshuai.huodong.model.HuoDongItemModel;
import com.beiing.tianshuai.tianshuai.huodong.model.HuoDongItemModelImpl;
import com.beiing.tianshuai.tianshuai.huodong.view.EventsCommonViewImpl;

import io.reactivex.disposables.Disposable;

/**
 * Created by magikliu on 2017/7/14.
 */

public class EventsItemPresenter extends BasePresenter implements HuoDongItemPresenterImpl, HuoDongItemModel.OnRequestListener {

    public static final String TAG = "EventsItemPresenter";

    private HuoDongItemModelImpl mModel;
    private EventsCommonViewImpl mView;

    public EventsItemPresenter(EventsCommonViewImpl mView) {
        this.mView = mView;
        this.mModel = new HuoDongItemModel(this);
    }

    @Override
    public void getHuoDong(String id, int firstRow, int listRows, int type) {
        mView.showProgress();
        mModel.getHuoDong(id, firstRow, listRows, type);
    }

    @Override
    public void addSubscription(Disposable disposable) {
        super.addSubscription(disposable);
    }

    @Override
    public void onUnsubscribe() {
        super.onUnsubscribe();
    }

    @Override
    public void onSuccess(HuoDongItemBean bean, int type) {
        if (type == 0){     //普通获取数据
            mView.onRequestSuccess(bean);
        } else {
            mView.refreshHuodongList(bean);
        }

        mView.hideProgress();
    }

    @Override
    public void onError(Throwable e) {
        mView.onRequestFailed(e);
    }


}
